#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 10;
int x, y;
int dis[N];

void bfs() {
	memset(dis, -1, sizeof dis);
	dis[x] = 0;
	queue<int> q;
	q.push(x);
	while (q.size()) {
		int x = q.front(); q.pop();
		if (x + 1 < N && dis[x + 1] == -1) {
			dis[x + 1] = dis[x] + 1;
			q.push(x + 1);
		}
		if (x - 1 > 0 && dis[x - 1] == -1) {
			dis[x - 1] = dis[x] + 1;
			q.push(x - 1);
		}
		if (x * 2 < N && dis[x * 2] == -1) {
			dis[x * 2] = dis[x] + 1;
			q.push(x * 2);
		}
		if (x == y) {
			cout << dis[y] << endl;
			return;
		}
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		cin >> x >> y;
		bfs();
	}
	return 0;
}